DateInput=(function($){function DateInput(el,opts){if(typeof(opts)!="object"){opts={};}$.extend(this,DateInput.DEFAULT_OPTS,opts);this.input=$(el);this.bindMethodsToObj("show","hide","hideIfClickOutside","hideOnEsc","selectDate","prevMonth","nextMonth");this.build();this.selectDate();this.hide();}DateInput.DEFAULT_OPTS={month_names:["January","February","March","April","May","June","July","August","September","October","November","December"],short_month_names:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],short_day_names:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],start_of_week:1};DateInput.prototype={build:function(){this.monthNameSpan=$('');var monthNav=$('

').append($(' ').click(this.prevMonth),this.monthNameSpan,$(' ').click(this.nextMonth));var tableShell="";$(this.adjustDays(this.short_day_names)).each(function(){tableShell+="";});tableShell+="
"+this+"
";this.dateSelector=this.rootLayers=$('
').append(monthNav,tableShell).insertAfter(this.input);if($.browser.msie&&$.browser.version<7){this.ieframe=$('').insertBefore(this.dateSelector);this.rootLayers=this.rootLayers.add(this.ieframe);}this.tbody=$("tbody",this.dateSelector);this.input.change(this.bindToObj(function(){this.selectDate();}));},selectMonth:function(date){this.currentMonth=new Date(date.getFullYear(),date.getMonth(),1);var rangeStart=this.rangeStart(date),rangeEnd=this.rangeEnd(date);var numDays=this.daysBetween(rangeStart,rangeEnd);var dayCells="";for(var i=0;i<=numDays;i++){var currentDay=new Date(rangeStart.getFullYear(),rangeStart.getMonth(),rangeStart.getDate()+i,12,0);if(this.isFirstDayOfWeek(currentDay)){dayCells+="";}if(currentDay.getMonth()==date.getMonth()){dayCells+=''+currentDay.getDate()+"";}else{dayCells+=''+currentDay.getDate()+"";}if(this.isLastDayOfWeek(currentDay)){dayCells+="";}}this.monthNameSpan.empty().append(this.monthName(date)+" "+date.getFullYear());this.tbody.empty().append(dayCells);$("a",this.tbody).click(this.bindToObj(function(event){this.selectDate(this.stringToDate($(event.target).parent().attr("date")));this.hide();return false;}));$("td[date='"+this.dateToString(new Date())+"']",this.tbody).addClass("today");},selectDate:function(date){if(typeof(date)=="undefined"){date=this.stringToDate(this.input.val());}if(date){this.selectedDate=date;this.selectMonth(date);var stringDate=this.dateToString(date);$('td[date="'+stringDate+'"]',this.tbody).addClass("selected");if(this.input.val()!=stringDate){this.input.val(stringDate).change();}}else{this.selectMonth(new Date());}},show:function(){this.rootLayers.css("display","block");this.setPosition();this.input.unbind("focus",this.show);$("a:last",this.dateSelector).blur(this.hide);$([window,document.body]).click(this.hideIfClickOutside).keyup(this.hideOnEsc);},hide:function(){this.rootLayers.css("display","none");$([window,document.body]).unbind("click",this.hideIfClickOutside).unbind("keyup",this.hideOnEsc);$("a:last",this.dateSelector).unbind("blur",this.hide);this.input.focus(this.show);},hideIfClickOutside:function(event){if(event.target!=this.input[0]&&!this.insideSelector(event)){this.hide();}},hideOnEsc:function(event){if(event.keyCode==27){this.hide();}},stringToDate:function(string){var matches;if(matches=string.match(/^(\d{1,2}) ([^\s]+) (\d{4,4})$/)){return new Date(matches[3],this.shortMonthNum(matches[2]),matches[1],12,0);}else{return null;}},dateToString:function(date){return date.getDate()+" "+this.short_month_names[date.getMonth()]+" "+date.getFullYear();},setPosition:function(){var offset=this.input.offset();this.rootLayers.css({top:offset.top+this.input.outerHeight(),left:offset.left});if(this.ieframe){this.ieframe.css({width:this.dateSelector.outerWidth(),height:this.dateSelector.outerHeight()});}},moveMonthBy:function(amount){this.selectMonth(new Date(this.currentMonth.setMonth(this.currentMonth.getMonth()+amount)));},prevMonth:function(){this.moveMonthBy(-1);return false;},nextMonth:function(){this.moveMonthBy(1);return false;},monthName:function(date){return this.month_names[date.getMonth()];},insideSelector:function(event){var offset=this.dateSelector.offset();offset.right=offset.left+this.dateSelector.outerWidth();offset.bottom=offset.top+this.dateSelector.outerHeight();return event.pageYoffset.top&&event.pageXoffset.left;},bindToObj:function(fn){var self=this;return function(){return fn.apply(self,arguments);};},bindMethodsToObj:function(){for(var i=0;i